package com.bub.pay.api;

import com.bub.pay.core.interceptor.mybatis.CommonFillInterceptor;
import org.apache.ibatis.plugin.Interceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

@ComponentScan(basePackages = {"com.bub.pay"})
@SpringBootApplication
public class MerchantApplication {

	private static final Logger log = LoggerFactory.getLogger(MerchantApplication.class);
	
	public static void main(String[] args) throws UnknownHostException {
		SpringApplication app = new SpringApplication(MerchantApplication.class);
		Environment env = app.run(args).getEnvironment();
		log.info("----------------------------------------------------------");
		log.info("Application '{}' is running! Access URLs:", env.getProperty("spring.application.name"));
		log.info("Local:  http://127.0.0.1:{} ", env.getProperty("server.port"));
		log.info("External:  http://{}:{} ", InetAddress.getLocalHost().getHostAddress(),
				env.getProperty("server.port"));
		log.info("Application '{}' is running! Access URLs:", env.getProperty("spring.application.name"));
		log.info("----------------------------------------------------------");
	}

	@Bean
	public Interceptor commonFieldUpdateInterceptor() {
		return new CommonFillInterceptor();
	}

}
